﻿/*Copyright (C) 2011 by Marcin Kozlowski (naarkie@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VillageOfAres
{
    class Generator
    {
        int maxfood;
        int maxwarriors;
        int maxgold;
        int maxpopulation;
        decimal thingywarriors;
        //3 string arrays that are used for the generation of names
        //it basically just picks a random 'word' from each array,
        //then concatenates them together.
        string[] prefix = { "More", "Eis", "Dar", "Fler","Qua","Sur","Car" };
        string[] middle = { "en","lo","o","in","es","or","aren","of","ber","gretin","hertil" };
        string[] end = { "field", "stown", "sfield", "ton","dila","vet","ta"};

        public Generator(int maxfood, int maxwarriors, int maxgold, int maxpopulation)
        {
            this.maxfood = maxfood;
            this.maxwarriors = maxwarriors;
            this.maxpopulation = maxpopulation;
            this.maxgold = maxgold;
        }
        public Village GenerateVillage()
        {
            Random rng = new Random();
            string prefixname = prefix[rng.Next(prefix.Length)];
            string middlename = middle[rng.Next(middle.Length)];
            string endname = end[rng.Next(end.Length)];
            string name = prefixname + middlename + endname; //concatenationnnnnnnn~

            int population = rng.Next(maxpopulation) + 3; //have at least 3 people in the town
            int gold = rng.Next(maxgold);
            //so like each turn each villages gold = village population*10 or w/e
            //not sure how i'll do this.
            //in endturn method - "foreach village in villages"? Probably
            thingywarriors = Math.Round(population / 100m * 25m); //i have no clue. it breaks
            //if i dont put in the m's. Basically its saying make the village have
            //a quarter the warriors as the population
            int warriors = (int)thingywarriors;
            int food = rng.Next(maxfood) + population;
            int id = rng.Next(999) + 1;//ffs, get a proper id system!
            //atm 2 villages can have the same id. Which isn't very good :/
            return new Village(population, gold, warriors, food, name,id);
        }
    }
}
